/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */

package cn.qidisoft.edu.hzjt.controller.communityamateurhomework;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;

import cn.qidisoft.core.common.context.ApplicationContextConfigUtil;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.file.FileUtil;
import cn.qidisoft.edu.hzjt.annotation.SysLogger;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.model.BjxxClassMaterialFile;
import cn.qidisoft.edu.hzjt.model.CommunityAmateurWorkStudent;
import cn.qidisoft.edu.hzjt.model.CommunityAmateurWorkStudentAtt;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.Student;
import cn.qidisoft.edu.hzjt.service.ICommunityAmateurWorkStudentAttService;
import cn.qidisoft.edu.hzjt.service.ICommunityAmateurWorkStudentService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: CommunityAmateurWorkStudentController.java, v 0.1 2018年11月1日 上午10:50:34 hhl Exp $
 */

@Controller
@RequestMapping(value = "communityAmateurWorkStudent")
public class CommunityAmateurWorkStudentController {
    protected static final LoggerAdapter                             LOGGER = LoggerAdapterFactory
        .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    private ICommunityAmateurWorkStudentService                      communityAmateurWorkStudentService;

    @Autowired
    private ICommunityAmateurWorkStudentAttService                   communityAmateurWorkStudentAttService;

    private static Map<String, List<CommunityAmateurWorkStudentAtt>> picMap = new HashMap<String, List<CommunityAmateurWorkStudentAtt>>();

    private static String                                            upload = null;

    static {
        upload = ApplicationContextConfigUtil.getString("file.path", null);
    }

    @RequestMapping(value = "/index")
    public String index(ModelMap model, HttpServletRequest request) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            picMap.remove(String.valueOf(student.getXsid()));

            String zyid = request.getParameter("zyid");
            model.addAttribute("zyid", zyid);

            request.setAttribute("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "communityAmateurWorkStudent/communityAmateurWorkStudentList_Student";
    }

    @RequestMapping(value = "/List_Student")
    @ResponseBody
    public ResponseResult List(ModelMap model, HttpServletRequest request,
                               @RequestParam(value = "rows", required = false) String pageSize,
                               @RequestParam(value = "page", required = false) String currentPage,
                               @RequestParam(value = "zyid", required = false) Integer zyid,
                               CommunityAmateurWorkStudent data) {

        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            data.setLogo("99"); //学生端
            data.setZyid(zyid);
            Page page = new Page();
            page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
            page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));
            BaseController.setSortByColumn(request, "tt.createtime", "desc");
            if (request.getAttribute("orderField").equals("createtime")) {
                data.setOrderField("tt.createtime");
            } else if (request.getAttribute("orderField").equals("dxqs")) {
                data.setOrderField("tt.dxqs");
            } else if (request.getAttribute("orderField").equals("xz")) {
                data.setOrderField("tt.createtime");
            } else {
                data.setOrderField((String) request.getAttribute("orderField"));
            }
            data.setOrderFlag((String) request.getAttribute("orderFlag"));

            PaginationBean<CommunityAmateurWorkStudent> paginationBean = communityAmateurWorkStudentService
                .queryPageList(data, page);

            String path = request.getContextPath();
            String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                              + request.getServerPort() + path;

            java.util.List<CommunityAmateurWorkStudent> datalist = new ArrayList<CommunityAmateurWorkStudent>();
            if (paginationBean.getPageList() != null && !paginationBean.getPageList().isEmpty()) {
                for (CommunityAmateurWorkStudent r : paginationBean.getPageList()) {

                    CommunityAmateurWorkStudentAtt data1 = new CommunityAmateurWorkStudentAtt();
                    data1.setParentid(r.getXszyid());
                    List<CommunityAmateurWorkStudentAtt> dataList = communityAmateurWorkStudentAttService
                        .queryList(data1);
                    String xz = "";
                    if (dataList != null && !dataList.isEmpty()) {
                        for (CommunityAmateurWorkStudentAtt f : dataList) {
                            if (xz.length() > 0)
                                xz += ",";
                            xz += "&nbsp;<a href=\"" + basePath + "/DownLoadFileServlet?filename="
                                  + f.getFilename() + "&filepath=" + f.getFilepath() + "\">"
                                  + f.getFilename() + "<img src=\"" + basePath + "/img/down.png"
                                  + "\"/></a>";

                        }
                    }
                    r.setXz(xz);
                    datalist.add(r);
                }
            }

            ResponseResult result = new ResponseResult();
            if (paginationBean.getPageList().isEmpty()) {
                result.setRows(new ArrayList<CommunityAmateurWorkStudent>());
            } else {
                result.setRows(datalist);
            }
            result.setTotal(paginationBean.getTotalRecords());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }

    @RequestMapping(value = "/addInInt")
    public String add(ModelMap model, HttpServletRequest request) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            picMap.remove(String.valueOf(student.getXsid()));

            model.addAttribute("xm", student.getXm());
            model.addAttribute("zyid", request.getParameter("zyid"));

            request.setAttribute("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "communityAmateurWorkStudent/add_CommunityAmateurWorkStudent";
    }

    @RequestMapping(value = "/details")
    public String details(ModelMap model, HttpServletRequest request,
                          @RequestParam(value = "id", required = false) Integer id) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            picMap.remove(String.valueOf(student.getXsid()));

            CommunityAmateurWorkStudent data = new CommunityAmateurWorkStudent();
            data.setXszyid(id);
            data = communityAmateurWorkStudentService.queryByPK(data);
            model.addAttribute("data", data);
            model.addAttribute("zyid", request.getParameter("zyid"));

            // 获取附件信息
            CommunityAmateurWorkStudentAtt att = new CommunityAmateurWorkStudentAtt();
            att.setParentid(id);
            List<CommunityAmateurWorkStudentAtt> attList = communityAmateurWorkStudentAttService
                .queryList(att);
            request.setAttribute("dataList", attList);

            return "communityAmateurWorkStudent/details_CommunityAmateurWorkStudent";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "团校作业管理信息", moduleName = "团校作业管理", method = "新增保存")
    @RequestMapping(value = "/add")
    public String add(ModelMap model, HttpServletRequest request,
                      CommunityAmateurWorkStudent data) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setXsid(student.getXsid());
            data.setCreatorid(student.getXsid());
            data.setCreatetime(new Date());
            data.setCreatorname(student.getXm());
            data.setZt(0);
            data.setLx(2);
            communityAmateurWorkStudentService.add(data);

            /*   CommunityAmateurWorkStudent data1 = new CommunityAmateurWorkStudent();
            data1.setGid(gid);
            data1 = communityAmateurWorkStudentService.queryByPK(data);*/

            List<CommunityAmateurWorkStudentAtt> docFileResourceList = picMap
                .get(String.valueOf(student.getXsid()));
            if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
                MultipartFile file = null;
                Integer orders = 0;
                for (CommunityAmateurWorkStudentAtt r : docFileResourceList) {
                    file = r.getMufile();
                    String name = file.getOriginalFilename();// 获取上传文件名
                    InputStream in = r.getInputStream();// 获取文件对象
                    int pos = name.lastIndexOf(".");
                    String lastname = name.substring(pos, name.length());
                    // 文件保存的路径
                    String savePath = upload + File.separator
                                      + Constant.CONTRIBUTIONATT_RESOURCE_TX_ZYStudent + "/"
                                      + student.getXsid() + "/"
                                      + DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd")
                                      + File.separator + r.getGid();
                    FileUtil.saveFile(savePath, in, r.getGid() + lastname);
                    r.setParentid(data.getXszyid());
                    r.setFileid(r.getGid());// 附件id
                    r.setFilename(name);
                    r.setOrders(orders);
                    communityAmateurWorkStudentAttService.add(r);
                    orders++;
                }
            }

        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        String action = request.getParameter("action");
        model.addAttribute("zyid", request.getParameter("zyid"));
        if (action.equals("1")) {
            return "redirect:details?id=" + data.getXszyid();
        } else if (action.equals("2")) {
            return "redirect:addInInt";
        }
        return null;
    }

    @RequestMapping(value = "/updateToview", method = RequestMethod.GET)
    public String updateToview(ModelMap model, HttpServletRequest request,
                               @RequestParam(value = "id") Integer id) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            picMap.remove(String.valueOf(student.getXsid()));

            CommunityAmateurWorkStudent data = new CommunityAmateurWorkStudent();
            data.setXszyid(id);
            data = communityAmateurWorkStudentService.queryByPK(data);
            model.addAttribute("data", data);

            // 获取附件信息
            CommunityAmateurWorkStudentAtt att = new CommunityAmateurWorkStudentAtt();
            att.setParentid(id);
            List<CommunityAmateurWorkStudentAtt> attList = communityAmateurWorkStudentAttService
                .queryList(att);
            request.setAttribute("dataList", attList);

            return "communityAmateurWorkStudent/update_CommunityAmateurWorkStudent";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "团校作业管理信息", moduleName = "团校作业管理", method = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(ModelMap model, HttpServletRequest request,
                         CommunityAmateurWorkStudent data) {
        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            communityAmateurWorkStudentService.update(data);

            List<CommunityAmateurWorkStudentAtt> docFileResourceList = picMap
                .get(String.valueOf(student.getXsid()));
            if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
                MultipartFile file = null;
                Integer orders = 0;
                for (CommunityAmateurWorkStudentAtt r : docFileResourceList) {
                    file = r.getMufile();
                    String name = file.getOriginalFilename();// 获取上传文件名
                    InputStream in = r.getInputStream();// 获取文件对象
                    int pos = name.lastIndexOf(".");
                    String lastname = name.substring(pos, name.length());
                    // 文件保存的路径
                    String savePath = upload + File.separator
                                      + Constant.CONTRIBUTIONATT_RESOURCE_TX_ZYStudent + "/"
                                      + student.getXsid() + "/"
                                      + DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd")
                                      + File.separator + r.getGid();
                    FileUtil.saveFile(savePath, in, r.getGid() + lastname);
                    r.setParentid(data.getXszyid());
                    r.setFileid(r.getGid());// 附件id
                    r.setFilename(name);
                    r.setOrders(orders);
                    communityAmateurWorkStudentAttService.add(r);
                    orders++;
                }
            }
            model.addAttribute("zyid", request.getParameter("zyid"));
            return "redirect:index";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "团校作业管理信息", moduleName = "团校作业管理", method = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(ModelMap model, HttpServletRequest request) {
        try {
            String[] idList = request.getParameter("idList").split(",");
            CommunityAmateurWorkStudent data = new CommunityAmateurWorkStudent();
            data.setIds(idList);
            communityAmateurWorkStudentService.delete(data);
            BaseController.setParameter("msg", "删除成功");
            model.addAttribute("zyid", request.getParameter("zyid"));
            return "redirect:index";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("删除 delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "团校作业管理信息", moduleName = "团校作业管理信息", method = "提交")
    @RequestMapping(value = "/btnSubmit")
    public String btnSubmit(ModelMap model, HttpServletRequest request,
                            @RequestParam(value = "id", required = false) Integer id) {
        try {
            CommunityAmateurWorkStudent data = new CommunityAmateurWorkStudent();
            data.setXszyid(id);
            data = communityAmateurWorkStudentService.queryByPK(data);
            data.setZt(1);
            communityAmateurWorkStudentService.update(data);
            model.addAttribute("id", id);
            model.addAttribute("zyid", request.getParameter("zyid"));
            return "redirect:/communityAmateurWorkStudent/details";
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    /**
     * 上传附件
     * 
     * @param file
     * @param request
     * @param response
     */
    @RequestMapping(value = "/source_upload", method = RequestMethod.POST)
    public @ResponseBody void loadFile(@RequestParam("file") MultipartFile file,
                                       HttpServletRequest request, HttpServletResponse response) {

        List<CommunityAmateurWorkStudentAtt> list = new ArrayList<CommunityAmateurWorkStudentAtt>();
        Student student = (Student) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<CommunityAmateurWorkStudentAtt> docFileResourceList = picMap
            .get(String.valueOf(student.getXsid()));
        // 本地env配置路径
        String path = Constant.UPLOADPATH;
        CommunityAmateurWorkStudentAtt docFile = new CommunityAmateurWorkStudentAtt();
        if (!file.isEmpty()) {
            // 文件的大小
            docFile
                .setFilesize(String.valueOf(FileUtil.FormetFileSize(Long.valueOf(file.getSize()))));

            String name = file.getOriginalFilename();// 获取上传文件名
            docFile.setFilename(name);
            String gid = UUID.randomUUID().toString();

            // 获取文件后缀名称
            String extend = FilenameUtils.getExtension(name);
            // 文件路径带后缀
            docFile.setFilepath(
                Constant.CONTRIBUTIONATT_RESOURCE_TX_ZYStudent + "/" + student.getXsid() + "/"
                                + DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd") + "/" + gid
                                + "/" + gid + "." + extend);
            // 全路径系统文件名称带点
            docFile
                .setSysfilepath(path + File.separator + gid + File.separator + gid + "." + extend);
            // 文件名称uuid
            docFile.setFilename(gid);
            // 上传时间
            /* docFile.setMsubmittime(new Date()); */
            //获取文件扩展名
            docFile.setExtension(FileUtil.getFileExtendName(name).toLowerCase());
            //获取文件类型
            docFile.setContenttype(FileUtil.getFileExtendName(name).toLowerCase());
            docFile
                .setFilesize(String.valueOf(FileUtil.FormetFileSize(Long.valueOf(file.getSize()))));// 获取文件大小
            // uuid
            docFile.setGid(gid);

            docFile.setMufile(file);
            try {
                docFile.setInputStream(file.getInputStream());
            } catch (IOException e) {
            }

            if (docFileResourceList != null && docFileResourceList.size() > 0) {
                docFileResourceList.add(docFile);
                picMap.put(String.valueOf(student.getXsid()), docFileResourceList);
            } else {
                list.add(docFile);
                picMap.put(String.valueOf(student.getXsid()), list);
            }
            LOGGER.info("附件上传成功！");
        }
        PrintWriter writer = null;
        try {

            BjxxClassMaterialFile docFile2 = new BjxxClassMaterialFile();
            docFile2.setFilepath(docFile.getFilepath());
            // 文件名称
            docFile2.setFilename(docFile.getFilename());
            docFile2.setSysfilepath(docFile.getSysfilepath());

            writer = (PrintWriter) response.getWriter();
            String json = JSONObject.toJSONString(docFile2);
            writer.write(json);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 新增删除服务器的文件
     * 
     * @param request
     * @return
     */
    @RequestMapping(value = "/deletefile", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> deleteFile(HttpServletRequest request) {

        Map<String, Object> dataMap = new HashMap<String, Object>();
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);

            // env配置路径
            String path = upload;

            String filepath = request.getParameter("filepath");
            LOGGER.info("文件的原始路径===" + filepath);
            // 文件的全路径
            String fullpath = null;
            // 文件名称
            String filename = null;
            // 文件名无后缀
            String fileNoSuffix = null;

            if (filepath.indexOf("prefix") == -1) {
                // 文件的文件名称
                fileNoSuffix = filepath.split(",")[0];
                String sec = filepath.split(",")[1];
                // 文件的后缀
                String suffix = sec.substring(sec.indexOf("."));
                // 文件名无后缀加上后缀
                filename = fileNoSuffix + suffix;
                // 文件的全路径
                fullpath = path + "/" + fileNoSuffix;
                // FileUtil.deleteFile(fullpath, filename);//删除文件目录下面的文件
                // FileUtils.forceDelete(new File(fullpath)); //删除文件目录
            } else {
                return dataMap;
            }

            List<CommunityAmateurWorkStudentAtt> noticeNewsFilepathList = picMap
                .get(String.valueOf(student.getXsid()));

            // 删除list里面前台删除的前台信息图片附件表
            if (noticeNewsFilepathList != null && !noticeNewsFilepathList.isEmpty()) {
                for (CommunityAmateurWorkStudentAtt noticenewsfilepath : noticeNewsFilepathList) {
                    if (noticenewsfilepath.getFilename().equals(fileNoSuffix)) {
                        noticeNewsFilepathList.remove(noticenewsfilepath);
                        break;
                    }
                }
            }
            // 先删除
            picMap.remove(String.valueOf(student.getXsid()));
            // 后添加
            picMap.put(String.valueOf(student.getXsid()), noticeNewsFilepathList);
            dataMap.put("success", "0000");
            return dataMap;
        } catch (Exception e) {
            dataMap.put("success", "-9999");
            return dataMap;
        }
    }

    /**
     * 修改删除图片
     * 
     * @param file
     * @param request
     * @param response
     */
    @RequestMapping(value = "/source_upload_update", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> source_upload_update(@RequestParam("id") String id,
                                                                  HttpServletRequest request,
                                                                  HttpServletResponse response) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        try {
            CommunityAmateurWorkStudentAtt data = new CommunityAmateurWorkStudentAtt();
            data.setFileid(id);
            data = communityAmateurWorkStudentAttService.queryByPK(data);
            communityAmateurWorkStudentAttService.delete(data);
            if (data != null) {
                String upload = Constant.UPLOADPATH;
                int idlength = data.getFileid().lastIndexOf("");
                int pos = data.getFilepath().lastIndexOf(".");
                String filepath = data.getFilepath().substring(0, pos - idlength - 1);
                File file = new File(upload + File.separator + filepath);
                if (file.isDirectory()) {//判断file是否是文件目录 若是返回TRUE  
                    String name[] = file.list();//name存储file文件夹中的文件名  
                    for (int i = 0; i < name.length; i++) {
                        File f = new File(upload + File.separator + filepath, name[i]);//此时就可得到文件夹中的文件  
                        f.delete();//删除文件  
                    }
                    FileUtils.forceDelete(new File(upload + File.separator + filepath)); //最后删除文件目录
                }
                // FileTool.deleteFile(file);
            }
            dataMap.put("success", "0000");
        } catch (Exception e) {
            LOGGER.error("调用services网络异常", e);
            dataMap.put("success", "-9999");
        }
        return dataMap;
    }

    /*******************************************************************************************************************************************************************/
    /*
     * 教师端查看作业
     */
    @RequestMapping(value = "/index_Teachers")
    public String index_Teachers(ModelMap model, HttpServletRequest request) {
        try {
            String zyid = request.getParameter("zyid");
            model.addAttribute("zyid", zyid);

        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "communityAmateurWorkStudent/communityAmateurWorkStudentList_Teachers";
    }

    @RequestMapping(value = "/List_Teachers")
    @ResponseBody
    public ResponseResult List_Teachers(ModelMap model, HttpServletRequest request,
                                        @RequestParam(value = "rows", required = false) String pageSize,
                                        @RequestParam(value = "page", required = false) String currentPage,
                                        @RequestParam(value = "zyid", required = false) Integer zyid,
                                        CommunityAmateurWorkStudent data) {

        try {
            data.setLogo("100"); //老师端
            data.setZyid(zyid);
            Page page = new Page();
            page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
            page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));
            BaseController.setSortByColumn(request, "s.createtime", "desc");
            if (request.getAttribute("orderField").equals("createtime")) {
                data.setOrderField("s.createtime");
            } else if (request.getAttribute("orderField").equals("dxqs")) {
                data.setOrderField("x.dxqs");
            } else if (request.getAttribute("orderField").equals("xz")) {
                data.setOrderField("s.createtime");
            } else {
                data.setOrderField((String) request.getAttribute("orderField"));
            }
            data.setOrderFlag((String) request.getAttribute("orderFlag"));

            PaginationBean<CommunityAmateurWorkStudent> paginationBean = communityAmateurWorkStudentService
                .queryPageList(data, page);

            String path = request.getContextPath();
            String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                              + request.getServerPort() + path;

            java.util.List<CommunityAmateurWorkStudent> datalist = new ArrayList<CommunityAmateurWorkStudent>();
            if (paginationBean.getPageList() != null && !paginationBean.getPageList().isEmpty()) {
                for (CommunityAmateurWorkStudent r : paginationBean.getPageList()) {

                    CommunityAmateurWorkStudentAtt data1 = new CommunityAmateurWorkStudentAtt();
                    data1.setParentid(r.getXszyid());
                    List<CommunityAmateurWorkStudentAtt> dataList = communityAmateurWorkStudentAttService
                        .queryList(data1);
                    String xz = "";
                    if (dataList != null && !dataList.isEmpty()) {
                        for (CommunityAmateurWorkStudentAtt f : dataList) {
                            if (xz.length() > 0)
                                xz += ",";
                            xz += "&nbsp;<a href=\"" + basePath + "/DownLoadFileServlet?filename="
                                  + f.getFilename() + "&filepath=" + f.getFilepath() + "\">"
                                  + f.getFilename() + "<img src=\"" + basePath + "/img/down.png"
                                  + "\"/></a>";

                        }
                    }
                    r.setXz(xz);
                    datalist.add(r);
                }
            }

            ResponseResult result = new ResponseResult();
            if (paginationBean.getPageList().isEmpty()) {
                result.setRows(new ArrayList<CommunityAmateurWorkStudent>());
            } else {
                result.setRows(datalist);
            }
            result.setTotal(paginationBean.getTotalRecords());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }
}
